package com.gk.study.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gk.study.entity.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    @Select("select * from b_order")
    List<Order> getList();
    @Insert("INSERT INTO b_order (status, order_time, username, title, cover, price) " +
            "SELECT 2,  #{formattedDateTime}, g.name, h.title, h.cover, h.price " +
            "FROM b_guest g, b_home h " +
            "WHERE g.id = #{userId} AND h.id = #{thingId}")
    int createOrderOne(@Param("userId") String userId, @Param("thingId") String thingId,@Param("formattedDateTime") String formattedDateTime);
    @Insert("INSERT INTO b_order (status, order_time, username, title, cover, price) " +
            "SELECT 1,  #{formattedDateTime}, g.name, h.title,h.cover, h.price " +
            "FROM b_guest g, b_home h " +
            "WHERE g.id = #{userId} AND h.id = #{thingId}")
    int cancelOrderOne(@Param("userId") String userId, @Param("thingId") String thingId,@Param("formattedDateTime") String formattedDateTime);

    List<Order> getUserOrderList(String userId, String status);

}

